﻿/// Name - Common.User v1.2
/// Description - User object.  Defines the user of the system
/// Programmer - Dan Yatzeck
/// Date coded - 10/26/2011
/// Arguments - None
/// Variables -
///     FirstName - User first name
///     LastName - User last name
///     EmailAddress - User email address, should be confirmed before allowed to continue
///     BirthDate - User birth date
///     Gender - User gender
///     Ethnicity - User ethnicity
///     Zipcode - User current zip code
///     Country - User current country
///     RegistrationConfirmed - Whether the user has confirmed their email address
///     QuestionaireLastPageCompleted - Last page completed in the questionaire, to be used
///         for resuming the questionaire if left off at a certain point
///     QuestionaireCompleted - Whether the user has completed the questionaire
///     UserRole - Type of user (admin, normal user, developer, etc.)
/// Files accessed by this code artifact - None
/// Files changed by this code artifact - None
/// I/O - None
/// Error Handling - None
/// Modifications -
///     1.0 - Initial coding
///     1.1 - (11/6/2011) Added QuestionaireLastPageCompleted and QuestionaireCompleted 
///     1.2 - (11/15/2011) Added UserRole
/// Known Faults -
///     1.0 - None known
///     1.1 - None known
///     1.2 - None known

using System;

namespace Common
{
    /// <summary>
    /// Defines a user of the system
    /// </summary>
    public class User
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string EmailAddress { get; set; }
        public DateTime BirthDate { get; set; }
        public string Gender { get; set; }
        public string Ethnicity { get; set; }
        public string Zipcode { get; set; }
        public string Country { get; set; }

        public bool RegistrationConfirmed { get; set; }

        public int QuestionaireLastPageCompleted { get; set; }
        public bool QuestionaireCompleted { get; set; }

        public UserRole UserRole { get; set; }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="firstName">User first name</param>
        /// <param name="lastName">User last name</param>
        /// <param name="emailAddress">User email address</param>
        /// <param name="birthdate">User birth date</param>
        /// <param name="gender">User gender</param>
        /// <param name="ethnicity">User ethnicity</param>
        /// <param name="zipcode">User current zip code</param>
        /// <param name="country">User current country</param>
        public User(string firstName, 
                    string lastName, 
                    string emailAddress,
                    DateTime birthdate,
                    string gender,
                    string ethnicity,
                    string zipcode,
                    string country
                    )
        {
            FirstName = firstName;
            LastName = lastName;
            EmailAddress = emailAddress;
            BirthDate = birthdate;
            Gender = gender;
            Ethnicity = ethnicity;
            Zipcode = zipcode;
            Country = country;
        }

        public User()
        {
            // TODO: Complete member initialization
        }

        /// <summary>
        /// Determines age based on birthdate and current date
        /// </summary>
        public int Age
        {
            get
            {
                int age = 0;
                if (DateTime.Today.Month < this.BirthDate.Month ||
                    (DateTime.Today.Month == this.BirthDate.Month &&
                        DateTime.Today.Day < this.BirthDate.Day))
                {
                    age = DateTime.Today.Year - this.BirthDate.Year - 1;
                }
                else
                {
                    age = DateTime.Today.Year - this.BirthDate.Year;
                }
                return age;
            }
        }

        public Guid UserId { get; set; }
    }
}
